package org.springblade.modules.admin.vo.plan;

import cn.hutool.core.convert.Convert;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.entity.MaintainPlanTemplate;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description 保养工单基础信息
 * @Author ysq
 * @Date 2023/12/20
 */
@Data
public class MaintainPlanBaseInfoVO {

	@ApiModelProperty(value = "工单id")
	private Long planId;

	@ApiModelProperty(value = "工单执行时间")
	private String planDate;

	@ApiModelProperty(value = "电梯id")
	private Long elevatorId;

	@ApiModelProperty(value = "电梯位置")
	private String elevatorAddress;

	@ApiModelProperty(value = "项目名称")
	private String buildingName;

	@ApiModelProperty(value = "保养类型")
	private String templateName;

	@ApiModelProperty(value = "计划执行人")
	private String userName;

	@ApiModelProperty(value = "电梯计划")
	private String taskPlanName;

	public void setTemplateName(String templateName) {
		if(Func.isNotEmpty(templateName) && templateName.contains("%")){
			List<String> strings = Func.toStrList(templateName);
			List<MaintainPlanTemplate> list = new ArrayList<>(10);
			for (String str :strings) {
				String[] split = str.split("%");
				MaintainPlanTemplate maintainPlanTemplate = new MaintainPlanTemplate();
				maintainPlanTemplate.setTemplateName(split[1]);
				maintainPlanTemplate.setSort(Convert.toInt(split[2],0));
				list.add(maintainPlanTemplate);
			}
			List<String> collect = list.stream().sorted(Comparator.comparing(MaintainPlanTemplate::getSort)).map(MaintainPlanTemplate::getTemplateName).collect(Collectors.toList());
			this.templateName = String.join(",",collect);
		}else {
			this.templateName = templateName;
		}
	}

}
